import sim.engine.*;
import sim.display.*;
import sim.portrayal.*;
import sim.portrayal.grid.*;
import sim.portrayal.simple.*;

import java.awt.*;

import javax.swing.*;

public class RebellionUI extends GUIState{
	
	public RebellionUI(){
		super(new Rebellion(System.currentTimeMillis()));
	}
	
	public RebellionUI(SimState state){
		super(state);
	}
	
	public static String getName(){
		return "Rebellion";
	}
	
	public Display2D display;
	public JFrame displayFrame;
	SparseGridPortrayal2D gridPortrayal = new SparseGridPortrayal2D();
	
	@SuppressWarnings("deprecation")
	public void init(Controller c){
		super.init(c);
		
		//Make 2D display
		Rebellion sch = (Rebellion)state;
		display = new Display2D(sch.gridWidth * 4, sch.gridHeight * 4, this, 1);
		displayFrame = display.createFrame();
		c.registerFrame(displayFrame);
		
		//Attach the portrayals
		display.attach(gridPortrayal, "Agents");
		
		//specify the backdrop color
		display.setBackdrop(Color.black);
		
		displayFrame.setVisible(true);	
	}
	
	public void setupPortrayals(){
		//tell portrayals what to portray and how to portray them
		gridPortrayal.setField(((Rebellion)state).grid);
		//gridPortrayal.setPortrayalForClass(Civilian.class, new OvalPortrayal2D(Color.green));
		gridPortrayal.setPortrayalForClass(Civilian.class, new CivilianPortrayal());
		gridPortrayal.setPortrayalForClass(Cop.class, new RectanglePortrayal2D(Color.blue));
		gridPortrayal.setPortrayalForNull(new SimplePortrayal2D());
		
		display.reset();	//reschedule the displayer
		display.repaint();	//redraw the display
	}
	
	public void start(){
		super.start();
		setupPortrayals();
	}
	
	public void load(SimState state){
		super.load(state);
		setupPortrayals();
	}
	
	public Object getSimulationInspectedObject() { return state; }
	
	public static void main(String[] args){
		RebellionUI rebUI = new RebellionUI();
		Console c = new Console(rebUI);
		c.setVisible(true);
	}
}
